import QtQml 2.15
import QtQuick 2.15
import QtQuick.Layouts 1.15
import org.ukui.quick.items 1.0

Item {
    id: root
    property alias iconSource: image.source
    // property alias nameText: nameText.text
    property string widgetId: ""
    width:mainLayout.width
    height: mainLayout.height

    ColumnLayout {
        id: mainLayout
        spacing: 0
        Image {
            id: image
            Layout.alignment: Qt.AlignHCenter
            Layout.preferredWidth: 270
            Layout.preferredHeight: 113
            sourceSize.width: 1024
            sourceSize.height: 1024
            fillMode: Image.PreserveAspectFit
        }
    }
    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        Menu {
            id: menu
            transientParent: parent
            content: [
                MenuItem {
                    text: qsTr("Add to Panel")
                    onClicked: {
                        Window.addToPanel(root.widgetId)
                    }
                },
                MenuItem {
                    text: qsTr("Remove from Panel")
                    onClicked: {
                        Window.removeFromPanel(root.widgetId)
                    }
                }
            ]
        }
        onClicked: {
            if (mouse.button === Qt.RightButton) {
                menu.open();
            }
        }
    }
}
